package com.heyi.nettylong.common.util;

import com.heyi.nettylong.common.protobuf.Command;
import com.heyi.nettylong.common.protobuf.Message;

/**
 * @author dengfeng
 * @date 2022/4/110:57
 */
public class MessageUtil {

    public static Message.MessageBase build(String clientId, Command.CommandType cmd, String data) {

        return build(0, clientId, cmd, data, null);
    }

    public static Message.MessageBase build(int msgId, String clientId, Command.CommandType cmd, String data) {

        return build(msgId, clientId, cmd, data, null);
    }

    /** 构建普通消息，msgid为0
     * @Date: 2019/2/23 13:25
     * @param
     */
    public static Message.MessageBase build(String clientId, Command.CommandType cmd, String data, String token) {

        return build(0, clientId, cmd, data, token);
    }

    /** 构建要返回的消息，给入msgid
     * @Date: 2019/2/23 13:25
     * @param
     */
    public static Message.MessageBase build(int msgId, String clientId, Command.CommandType cmd, String data, String token){

        Message.MessageBase.Builder msg = Message.MessageBase.newBuilder()
                .setClientId(clientId)
                .setCmd(cmd)
                .setData(data)
                .setMsgId(msgId);
        if(token != null){
            msg.setToken(token);
        }
        return msg.build();
    }
}
